import 'package:flutter/material.dart';
import 'package:flutter_app/api/api.dart' as api;
import 'package:flutter_app/ui/pages/gategoryInfoList.dart';

class FindPage extends StatefulWidget {
  @override
  FindPageState createState() {
    return new FindPageState();
  }

  const FindPage();
}

class FindPageState extends State<FindPage> {
  List<dynamic> _data;

  @override
  Widget build(BuildContext context) {
    return new Container(
      child: new ListView.builder(
          itemCount: _data == null ? 0 : _data.length,
          itemBuilder: (ctx, idx) {
            return Container(
                margin: const EdgeInsets.only(bottom: 1.0),
                color: Colors.white,
                padding: const EdgeInsets.only(
                    left: 20.0, right: 20.0, top: 10.0, bottom: 10.0),
                child: GestureDetector(
                  onTap: () {
                    Navigator
                        .of(context)
                        .push(new MaterialPageRoute(builder: (xtc) {
                      return new CategoryInfoListPage(
                          _data[idx]['id'], _data[idx]['name']);
                    }));
                  },
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Text(_data[idx]['name']),
                    ],
                  ),
                ));
          }),
    );
  }

  @override
  void initState() {
    super.initState();
    api.getClassification(_onClassificationLoad);
  }

  void _onClassificationLoad(dynamic data) {
    setState(() {
      this._data = data;
    });
  }
}
